package model.agent.question

import java.util.ArrayList;
import java.util.Collections;

class MultiSelectQuestion extends AbstractQuestion implements QuestionInterface {
	
	

	def baseValue = 1

	ArrayList<String> options = []

	def valueSep = QuestionSet.valueSep

	def questionSep = QuestionSet.multiSep

	float answer(String ans){
		if(options.contains(ans.replace(" ","").trim())){
			lastResult = baseValue
			return lastResult
		}
	}

	@Override
	public float answer(AbstractList ans) {
		ans = ans.collect {it.trim().replace(" ","");}
		def result = options.intersect(ans)
		lastResult = baseValue + (result.size()-1)
		return lastResult
		
	}

	@Override
	public ArrayList<String> getOptions() {
		return options;
	}



	def MultiSelectQuestion(String qString){
	

		questionString = qString.replace(" ","").trim()

		// 提取基础值
		def parts = questionString.split(valueSep)
		baseValue = parts[1].toFloat()

		// 提取问题
		options = parts[0].split(questionSep)

	}

}